package com.jboost.modules.app.util;

import com.jboost.modules.app.constant.Strategy;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.applet.AppletContext;
import java.util.HashMap;
import java.util.Map;

@Component
@AllArgsConstructor
public class StrategyFactory implements ApplicationContextAware {
    static Map<String, Strategy> strategyMap = new HashMap<>();
    public static Object  invokeStrategy(Object object,String type) throws Exception {
        return strategyMap.get(type).invokeStrategy(object);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        strategyMap.putAll(applicationContext.getBeansOfType(Strategy.class));
    }
}
